<?php
/**
 * Created by Engineer CuiLiwu.
 * Project: deal.
 * Date: 2018/6/23-16:51
 * License Hangzhou orce Technology Co., Ltd. Copyright © 2018
 */

namespace App\Http\Controllers\Backend\Service;

use App\ConstDir\ErrorConst;
use App\Http\Controllers\Backend\BaseController;
use App\Repository\Models\Orders;
use App\Repository\Repositories\Interfaces\OrdersRepository;
use Illuminate\Http\Request;
use Prettus\Repository\Criteria\RequestCriteria;

/**
 * 服务订单管理控制器
 *
 * @package App\Http\Controllers\Backend
 */
class ServiceOrderController extends BaseController
{
    /**
     * @var OrdersRepository
     */
    protected $orders_repo;


    public function __construct(OrdersRepository $orders_repo, Request $request)
    {
        parent::__construct();
        $this->orders_repo = $orders_repo;

        //用户只能操作自身所属数据
        $this->orders_repo->scopeQuery(function ($query) {
            return $query->where('order_type',6);
        });
    }

    public function index(Request $request)
    {
        $orders = $this->orders_repo->paginate($this->perPage);
        return $this->success(ErrorConst::SUCCESS_CODE, $orders, true);
    }

    public function show($id)
    {
//        $order = $this->orders_repo->with(['shop', 'user', 'orderProducts', 'orderExpress'])->find($id);
//        return $this->success(ErrorConst::SUCCESS_CODE, $order['data']);
    }

    public function store()
    {
        //后台无订单创建
    }

    public function update(Request $request, $id)
    {
//        $this->validate($request, [
//            'order_status' => 'integer|in:' . Orders::ORDER_STATUS_CANCEL,
//        ]);
//        $data = $request->all(['order_status']);
//
//        $ret = $this->orders_repo->update($data, $id);
//        if ($ret) {
//            return $this->success(ErrorConst::SUCCESS_CODE_MSG, ErrorConst::SUCCESS_CODE);
//        } else {
//            return $this->error(ErrorConst::FAILED_CODE_MSG);
//        }
    }

    public function delete($id)
    {
//        $ret = $this->orders_repo->delete($id);
//
//        if ($ret) {
//            return $this->success(ErrorConst::SUCCESS_CODE, ErrorConst::SUCCESS_CODE_MSG);
//        } else {
//            return $this->error(ErrorConst::FAILED_CODE);
//        }
    }

}